• Jump To … +
    main.js separate.js single.js web-apg-api.js main.js web-conv-api.js ast.js csv.js dangling-else.js display.js flags.js float.js limits.js main.js multiline-mode.js recursive.js replace.js rules.js split.js testonly.js trace.js udt.js unicode.js web-email.js word-boundaries.js main.js phone-number.js web-main.js web-phone-number.js main.js phone-number.js setup.js translate.js xml.js branch-fail-grammar.js main.js parent-mode-grammar.js setup.js universal-mode-grammar.js colors-app.js colors-callbacks.js colors.js main.js more-app.js more-setup.js more.js ast-callbacks.js bad-input.js basic.js ini-file.js main.js parser-callbacks.js setup.js trace.js anbncn.js and.js c-comment.js compound.js main.js nested.js not.js setup.js boundaries-grammar.js boundaries.js comment-grammar.js comment.js main.js negative-grammar.js negative.js positive-grammar.js positive.js setup.js main.js odata-grammar.js run.js setup.js area-code.js lookaround.js main.js phone-number.js setup.js simple.js all-operators.js default.js fancy-number.js limited-lines.js main.js select-operators.js select-rules.js setup.js main.js minimal.js parent-u.js parent.js phone-number.js setup.js stats.js trace.js universal-u.js universal.js callbacks.js grammar.js main.js parser.js writeHtml.js LICENSE.md README.md index.md
  • main.js

  • §
    /*  *************************************************************************************
     *   copyright: Copyright (c) 2021 Lowell D. Thomas, all rights reserved
     *     license: BSD-2-Clause (https://opensource.org/licenses/BSD-2-Clause)
     *   ********************************************************************************* */
  • §

    This is a demonstration of the look behind operators && and !!.

    module.exports = function main(args) {
      /* display the program arguments */
      console.log('look-behind args');
      console.dir(args);
    
      /* the help screen */
      let desc = '';
      desc += 'The "look-behind" example demonstrates the use of the look behind operators, && and !!\n';
      desc += 'Examine or run a debugger on this module, "apg-js-examples/src/look-behind/main.js" to study the example.\n';
      let help = '';
      help += 'Usage: npm run look-behind [-- arg]\n';
      help += '  arg: help       (or no arg) to display this help screen.\n';
      help += '       boundaries using look-behind to define word and line boundaries\n';
      help += '       comment    a cautionary example of using rules in look behind\n';
      help += '       negative   a simple example of using !!\n';
      help += '       positive   a simple example of using &&\n';
      if (!args[0]) {
        /* display the help screen and exit */
        console.log(desc);
        console.log(help);
        return;
      }
      switch (args[0]) {
        case 'help':
          console.log(help);
          return;
        case 'boundaries':
          console.log();
          console.log('Demonstrate: using look-behind to define word and line boundaries');
          require('./boundaries');
          break;
        case 'comment':
          console.log();
          console.log('Demonstrate: a cautionary example of using rules in look behind');
          require('./comment');
          break;
        case 'negative':
          console.log();
          console.log('Demonstrate: a simple example of using !!');
          require('./negative');
          break;
        case 'positive':
          console.log();
          console.log('Demonstrate: a simple example of using &&');
          require('./positive');
          break;
        case 'all':
          console.log();
          console.log('Demonstrate: using look-behind to define word and line boundaries');
          require('./boundaries');
          console.log();
          console.log('Demonstrate: a cautionary example of using rules in look behind');
          require('./comment');
          console.log();
          console.log('Demonstrate: a simple example of using !!');
          require('./negative');
          console.log();
          console.log('Demonstrate: a simple example of using &&');
          require('./positive');
          break;
        default:
          console.log(`unrecognized argument: ${args[0]}`);
          console.log(help);
      }
    };